package com.chaos.meta.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chaos.meta.entity.User;
import com.chaos.meta.mapper.UserMapper;
import com.chaos.meta.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.DoubleSummaryStatistics;
import java.util.List;
import java.util.LongSummaryStatistics;
import java.util.stream.Collectors;

/**
 * @author naicha
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findByName(String userName)
    {
        User user = new User();
        user.setUserName(userName);
        List<User> users = new ArrayList<>();

        LongSummaryStatistics summaryStatistics = users.stream().map(x->x.getUserId()).
                collect(Collectors.summarizingLong(Long::longValue));

        LongSummaryStatistics summaryStatistics2 = users.stream().
                collect(Collectors.summarizingLong(User::getUserId));

        RowBounds rowBounds = new RowBounds(0, 10);

        LambdaQueryWrapper<User> wrapper = Wrappers.lambdaQuery();
        wrapper.like(User::getUserName, userName).eq(User::getUserId, 1);

        Page<User> page = new Page<>(0, 10);
        userMapper.selectPage(page, wrapper);

        return userMapper.selectOne(wrapper);
    }
}